﻿namespace AssetsSys.model.Migrations
{
    using System;
    using System.Data.Entity.Migrations;
    
    public partial class CreateDb : DbMigration
    {
        public override void Up()
        {
            CreateTable(
                "dbo.Assets",
                c => new
                    {
                        Id = c.Guid(nullable: false),
                        AssetsNum = c.String(),
                        AssetsName = c.String(),
                        AssetsDescribe = c.String(),
                        Decimal = c.Decimal(nullable: false, precision: 18, scale: 2),
                        SourceId = c.Guid(nullable: false),
                        StatusId = c.Guid(nullable: false),
                        PrincipalId = c.Guid(nullable: false),
                        StorageId = c.Guid(nullable: false),
                        CreateTime = c.DateTime(nullable: false),
                        IsRemoved = c.Boolean(nullable: false),
                    })
                .PrimaryKey(t => t.Id)
                .ForeignKey("dbo.Users", t => t.PrincipalId)
                .ForeignKey("dbo.Sources", t => t.SourceId)
                .ForeignKey("dbo.Status", t => t.StatusId)
                .ForeignKey("dbo.Users", t => t.StorageId)
                .Index(t => t.SourceId)
                .Index(t => t.StatusId)
                .Index(t => t.PrincipalId)
                .Index(t => t.StorageId);
            
            CreateTable(
                "dbo.Users",
                c => new
                    {
                        Id = c.Guid(nullable: false),
                        UserName = c.String(),
                        Email = c.String(),
                        PassWord = c.String(),
                        PhoneNum = c.String(),
                        Stop = c.Boolean(nullable: false),
                        DepartmentId = c.Guid(nullable: false),
                        CreateTime = c.DateTime(nullable: false),
                        IsRemoved = c.Boolean(nullable: false),
                    })
                .PrimaryKey(t => t.Id)
                .ForeignKey("dbo.Departments", t => t.DepartmentId)
                .Index(t => t.DepartmentId);
            
            CreateTable(
                "dbo.Departments",
                c => new
                    {
                        Id = c.Guid(nullable: false),
                        DepartmentName = c.String(),
                        Permission = c.Int(nullable: false),
                        CreateTime = c.DateTime(nullable: false),
                        IsRemoved = c.Boolean(nullable: false),
                    })
                .PrimaryKey(t => t.Id);
            
            CreateTable(
                "dbo.Sources",
                c => new
                    {
                        Id = c.Guid(nullable: false),
                        SourceName = c.String(),
                        CreateTime = c.DateTime(nullable: false),
                        IsRemoved = c.Boolean(nullable: false),
                    })
                .PrimaryKey(t => t.Id);
            
            CreateTable(
                "dbo.Status",
                c => new
                    {
                        Id = c.Guid(nullable: false),
                        StatusName = c.String(),
                        CreateTime = c.DateTime(nullable: false),
                        IsRemoved = c.Boolean(nullable: false),
                    })
                .PrimaryKey(t => t.Id);
            
            CreateTable(
                "dbo.Fixups",
                c => new
                    {
                        Id = c.Guid(nullable: false),
                        AssetsId = c.Guid(nullable: false),
                        OldState = c.String(),
                        NewState = c.String(),
                        RepairId = c.String(),
                        FixId = c.String(),
                        CreateTime = c.DateTime(nullable: false),
                        IsRemoved = c.Boolean(nullable: false),
                        FixUsers_Id = c.Guid(),
                        RepairUsers_Id = c.Guid(),
                    })
                .PrimaryKey(t => t.Id)
                .ForeignKey("dbo.Assets", t => t.AssetsId)
                .ForeignKey("dbo.Users", t => t.FixUsers_Id)
                .ForeignKey("dbo.Users", t => t.RepairUsers_Id)
                .Index(t => t.AssetsId)
                .Index(t => t.FixUsers_Id)
                .Index(t => t.RepairUsers_Id);
            
            CreateTable(
                "dbo.Modifies",
                c => new
                    {
                        Id = c.Guid(nullable: false),
                        AssetsId = c.Guid(nullable: false),
                        OldState = c.String(),
                        NewState = c.String(),
                        ModifyState = c.String(),
                        AcceptId = c.String(),
                        ModifyId = c.String(),
                        CreateTime = c.DateTime(nullable: false),
                        IsRemoved = c.Boolean(nullable: false),
                        AcceptUsers_Id = c.Guid(),
                        ModifyUsers_Id = c.Guid(),
                    })
                .PrimaryKey(t => t.Id)
                .ForeignKey("dbo.Users", t => t.AcceptUsers_Id)
                .ForeignKey("dbo.Assets", t => t.AssetsId)
                .ForeignKey("dbo.Users", t => t.ModifyUsers_Id)
                .Index(t => t.AssetsId)
                .Index(t => t.AcceptUsers_Id)
                .Index(t => t.ModifyUsers_Id);
            
            CreateTable(
                "dbo.Types",
                c => new
                    {
                        Id = c.Guid(nullable: false),
                        TypeName = c.String(),
                        AgeLimit = c.Int(nullable: false),
                        CreateTime = c.DateTime(nullable: false),
                        IsRemoved = c.Boolean(nullable: false),
                    })
                .PrimaryKey(t => t.Id);
            
        }
        
        public override void Down()
        {
            DropForeignKey("dbo.Modifies", "ModifyUsers_Id", "dbo.Users");
            DropForeignKey("dbo.Modifies", "AssetsId", "dbo.Assets");
            DropForeignKey("dbo.Modifies", "AcceptUsers_Id", "dbo.Users");
            DropForeignKey("dbo.Fixups", "RepairUsers_Id", "dbo.Users");
            DropForeignKey("dbo.Fixups", "FixUsers_Id", "dbo.Users");
            DropForeignKey("dbo.Fixups", "AssetsId", "dbo.Assets");
            DropForeignKey("dbo.Assets", "StorageId", "dbo.Users");
            DropForeignKey("dbo.Assets", "StatusId", "dbo.Status");
            DropForeignKey("dbo.Assets", "SourceId", "dbo.Sources");
            DropForeignKey("dbo.Assets", "PrincipalId", "dbo.Users");
            DropForeignKey("dbo.Users", "DepartmentId", "dbo.Departments");
            DropIndex("dbo.Modifies", new[] { "ModifyUsers_Id" });
            DropIndex("dbo.Modifies", new[] { "AcceptUsers_Id" });
            DropIndex("dbo.Modifies", new[] { "AssetsId" });
            DropIndex("dbo.Fixups", new[] { "RepairUsers_Id" });
            DropIndex("dbo.Fixups", new[] { "FixUsers_Id" });
            DropIndex("dbo.Fixups", new[] { "AssetsId" });
            DropIndex("dbo.Users", new[] { "DepartmentId" });
            DropIndex("dbo.Assets", new[] { "StorageId" });
            DropIndex("dbo.Assets", new[] { "PrincipalId" });
            DropIndex("dbo.Assets", new[] { "StatusId" });
            DropIndex("dbo.Assets", new[] { "SourceId" });
            DropTable("dbo.Types");
            DropTable("dbo.Modifies");
            DropTable("dbo.Fixups");
            DropTable("dbo.Status");
            DropTable("dbo.Sources");
            DropTable("dbo.Departments");
            DropTable("dbo.Users");
            DropTable("dbo.Assets");
        }
    }
}
